package tcp;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 短连接发多个请求怎么发
 * 加while
 **/
public class 短连接Client {
    public static void main(String[] args) throws IOException {
        while(true){
            Socket socket = new Socket("127.0.0.1", 9090);//拨号
            InputStream is = socket.getInputStream();
            Scanner scanner = new Scanner(is, "UTF-8");
            OutputStream os = socket.getOutputStream();
            OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
            PrintWriter printWriter = new PrintWriter(writer);
            //客户端先发送请求
            printWriter.printf("我是Java19班的\r\napple\r\n");
            printWriter.flush();
            //读取响应
            String header = scanner.nextLine();//读到的是 好的
            String word = scanner.nextLine();//苹果
            System.out.println(word);
            socket.close();//挂断电话
        }
    }
}
